package com.yx.shop.entitly;

import java.io.Serializable;

/**
 * @Classname PageBean
 * @Description TODO:
 * @Date 2021/05/07 16:57
 * @Created by yx
 */
public class PageBean implements Serializable {

    //1.起始页
    private Integer pageIndex;
    //2.页大小
    private Integer pageSize;
    //3.总页数
    private Integer totalPage;
    //4.总行数
    private Integer totalCount;
    //5.起始行数
    private Integer startRows;


    @Override
    public String toString() {
        return "PageBean{" +
                "pageIndex=" + pageIndex +
                ", pageSize=" + pageSize +
                ", totalPage=" + totalPage +
                ", totalCount=" + totalCount +
                ", startRows=" + startRows +
                '}';
    }

    public PageBean(Integer pageIndex, Integer pageSize, Integer totalCount) {
        this.totalCount = totalCount;
        //设置页大小
        if (pageSize < 1) {
            pageSize = 5;
        }else {
            this.pageSize = pageSize;
        }
        //设置总页数
//        this.totalPage = this.totalCount % this.pageSize == 0 ? this.totalCount / this.pageSize : (this.totalCount / this.pageSize) + 1;
        this.totalPage = (int) Math.ceil(this.totalCount / (double)this.pageSize);
        //设置当前页码
        if (pageIndex < 1) {
            pageIndex = 1;
        } else if (pageIndex > this.totalPage) {
            this.pageIndex = this.totalPage;
        } else {
            this.pageIndex = pageIndex;
        }
        //计算起始行
        this.startRows = (this.pageIndex - 1) * this.pageSize;
    }

    public Integer getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(Integer pageIndex) {
        this.pageIndex = pageIndex;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
    }

    public Integer getStartRows() {
        return startRows;
    }

    public void setStartRows(Integer startRows) {
        this.startRows = startRows;
    }
}
